/**
 * Constructor
 * @returns {ns.Connection}
 */
ns.Connection = function() {
	this.conn = new WebSocket("ws://localhost:8080/ws");
	this.conn.binaryType = "arraybuffer";
	this.conn.onopen = function(evt) {
		console.log('Connection opened.');
	};
	this.conn.onclose = function(evt) {
		console.log('Connection closed.');
	};
	this.conn.onmessage = function(e) {
		console.log(e.data);
		if (e.data instanceof ArrayBuffer) {
			s = "ArrayBuffer: " + e.data.byteLength + " [";
			var view = new Uint8Array(e.data);
			for ( var i = 0; i < view.length; ++i) {
				s += " " + view[i];
			}
			s += "]";
			console.log(s);
		}
	};
};

/**
 * Tests the websockets support
 * @param text
 */
ns.Connection.prototype.send = function(text) {
	this.conn.send(text);
};
